package com.spring.component.rabbitmq.listener;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

/**
 * @author liushihua
 * @since 2018年04月26日
 */
@Component
public class MyMessageListener implements ChannelAwareMessageListener {

  private final Logger log = LoggerFactory.getLogger(this.getClass());

  @Override
  public void onMessage(Message message, Channel channel) throws Exception {
    log.info("接收消息----{}", message.toString());
    log.info("{}--工作中...", Thread.currentThread().getName());
    Thread.sleep(300);
    log.info("{}--工作完成", Thread.currentThread().getName());
    // channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
  }
}
